package com.lenovo.testreport.test.server.api.controller;

import com.lenovo.testreport.general.service.GeneralReportService;
import com.lenovo.testreport.test.server.api.model.TestServiceApiReport;
import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * @author CJF
 * @date 2018/12
 * <p>
 * 主要对report主表进行操作，查询报告
 */
@Controller
@RequestMapping("/test/web/api/report")
public class ReportController {
    @Autowired
    @Qualifier("reportServiceImpl")
    private GeneralReportService service;

    //按时间和版本查找报告
    @RequestMapping("/FindAllReportByTime")
    public @ResponseBody
    List<TestServiceApiReport> FindAllReportByTime(HttpServletRequest request) {

        String version = "";
        if (request.getParameter("version") != "") {
            version = request.getParameter("version").replace("\"", "");
        }
        version += "%";
        List<TestServiceApiReport> list = service.findReportByTime(request.getParameter("tablename"), request.getParameter("start"), request.getParameter("end"), version);
        return list;
    }

    //按类型查找报告
    @RequestMapping("/FindByType")
    public @ResponseBody
    Object FindByType(HttpServletRequest request) {
        return service.findByType(request.getParameter("tablename"), request.getParameter("type"));
    }

    //查找所有版本号
    @RequestMapping("/FindAllVersion")
    public @ResponseBody
    List<String> FindAllVersion(HttpServletRequest request) {
        return service.findAllVersion(request.getParameter("tablename"));
    }
}
